package cn.bdqn.controller;

import cn.bdqn.bean.result.Result;
import cn.bdqn.bean.result.ResultCode;
import cn.bdqn.bean.result.ResultGenerator;
import cn.bdqn.domain.Floor;
import cn.bdqn.service.FloorService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/HM/floor")
public class FloorController {

    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    private FloorService floorService;

    /**
     * 获取 病区列表方法
     * @return
     */
    @GetMapping("/getFloorList")
    public Result<Map<String, Object>> getFloorList(){
        Map<String, Object> data = new HashMap<>();
        try {
            logger.info("进入了 getFloorList(获取病区列表) 方法");
            List<Floor> floors = floorService.queryAll();
            data.put("floors", floors);

        } catch (Exception e) {
            logger.error("getFloorList(获取病区列表) 方法 抛出了异常:" + e.getMessage());
            e.printStackTrace();
            return ResultGenerator.genFailResult("网络异常", ResultCode.INTERNAL_SERVER_ERROR);
        }
        return ResultGenerator.genSuccessResult(data);
    }
}
